/**
 * 
 */
package com.buss.core.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.buss.core.exception.LoginException;
import com.buss.core.model.User;
import com.buss.core.sysparam.SysStaticParam;




/**
 * @author 高小勇
 * 创建时间:2011-4-12
 * wcms2.0
 */
public class DefaultInterceptor extends HandlerInterceptorAdapter {

	public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler)
		throws Exception{
		boolean handleOk = super.preHandle(request, response, handler);
		if(handleOk){
			String url = request.getServletPath();
			User user =  (User)request.getSession().getAttribute(SysStaticParam.SESSION_USER);
			if(url.indexOf("/admin/") == 0 && url.indexOf("/admin/loginpage.") == -1 && 
					url.indexOf("/admin/login.") == -1 && url.indexOf("/admin/logout.") == -1){			
				if(user == null){
					throw new LoginException("你还没有登陆系统，不能进行此项操作!");
				}
			}
			System.out.println(url + "--------" + request.getServletPath());
			return true;
		}
		return false;
	}
	
}
